
// 注意这里的代码是在顶层作用域中存在的
console.dir( JSON );

console.log( JSON.constructor );

const provinces = [
    {  
        name: '陕西省' , 
        cities: [ 
            { 
                name: '西安市' , 
                countries: [ { name: '长安' } , { name: '未央' } ] 
            },
            { 
                name: '咸阳市' , 
                countries: [ { name: '秦都区' } , { name: '泾阳县' } ] 
            }
        ]
    }
];

let toStringListener = function(){
    let s = JSON.stringify( provinces ); // 将 对象或数组 转换为 字符串
    let ta = K.single( '[name=result]' );
    ta.value = s ;
}

let fromStringListener = function(){
    let ta = K.single( '[name=result]' );
    let s = ta.value ;
    let o = JSON.parse( s ); // 将字符串解析为 对象 或 数组
    console.dir( o );
}

let loadListener = function(){
    let toStringBtn = K.single( '.to-string' );
    K.on( toStringBtn , 'click' , toStringListener );
    // btn.addEventListener( 'click' , listener , false );


    let fromStringBtn = K.single( '.from-string' ); 
    K.on( fromStringBtn , 'click' , fromStringListener );
}

K.on( window , 'load' , loadListener );
// window.addEventListener( 'load' , loadListener , false );